package com.example.zqm.git72.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zqm.git72.JavaBean.DetailShaiTu;
import com.example.zqm.git72.JavaBean.Master;
import com.example.zqm.git72.R;
import com.squareup.picasso.Picasso;

import java.util.List;

//import com.example.zqm.git72.Activity.FoodActivity;

/**
 * Created by Administrator on 2017/3/6 0006.
 */

public class CommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private LayoutInflater mLayoutInflater;
   // private DetailShaiTu detailShaiTu;
    private List<DetailShaiTu.CommentEntity> mDataList;
    //构造方法
    public CommentAdapter(Context mContext,List<DetailShaiTu.CommentEntity> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_comment,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        //把viewhoder数据映射到
        DetailShaiTu.CommentEntity entity = mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.user_name.setText(entity.getReply_userid());
        viewHolder.reply.setText(entity.getReply());
        viewHolder.reply_time.setText(entity.getReply_time());

//        if(entity.getClass().equals("")){
//            Picasso.with(mContext).load("https://b-ssl.duitang.com/uploads/item/201409/03/20140903102455_SNNnA.png"
//            )
//                    .resize(50,50).into(viewHolder.userpic);
//        }else{
//            String picUrl = "http://172.24.10.175/workout/Uploads/" + entity.getThumb();
//
//            Picasso.with(mContext).load(picUrl.toString())
//                    .resize(50,50).into(viewHolder.userpic);
//        }
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView userpic;
        TextView user_name,reply_time,reply;
        //构造方法
        public ViewHolder(View itemView) {
            super(itemView);
            user_name = (TextView) itemView.findViewById
                    (R.id.user_name);
            userpic = (ImageView) itemView.findViewById
                    (R.id.userpic);
            reply=(TextView) itemView.findViewById(R.id.reply);
            reply_time = (TextView) itemView.findViewById
                    (R.id.reply_time);

        }
    }
}
